import { Component, Input, Injector, ViewChild } from '@angular/core';
import { NzDrawerRef } from 'ng-zorro-antd';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
import { AuditLogListDto } from '@abp/service-proxies/service-proxies';
import { AppComponentBase } from '@abp/components';
import * as _ from 'lodash';
import * as moment from 'moment';

@Component({
  selector: 'audit-log-detail-drawer',
  templateUrl: './audit-log-detail.component.html',
  styleUrls: ['./audit-log-detail.component.less'],
})
export class AuditLogDetailComponent extends AppComponentBase {
  @Input() auditLog: AuditLogListDto;

  constructor(injector: Injector, private drawerRef: NzDrawerRef) {
    super(injector);
  }

  ngOnInit() {
    console.log(this.auditLog);
    // this.userService.getUserForEdit(this.id).subscribe(userResult => {
    //   this.roles = userResult.roles;
    //   this.user = userResult.user;
    //   if (this.id) {
    //     this.useDefaultPassword = false;
    //   }
    // });
  }

  close(): void {
    this.drawerRef.close(false);
  }

  getExecutionTime(): string {
    return (
      moment(this.auditLog.executionTime).fromNow() +
      ' (' +
      moment(this.auditLog.executionTime).format('YYYY-MM-DD HH:mm:ss') +
      ')'
    );
  }

  getFormattedParameters(): string {
    const self = this;
    try {
      const json = JSON.parse(self.auditLog.parameters);
      return JSON.stringify(json, null, 4);
    } catch (e) {
      return self.auditLog.parameters;
    }
  }
}
